import store from '@/store'
import axios from 'axios'
import { Toast } from 'vant'
const request = axios.create({
  baseURL: 'https://toutiao.itheima.net/',
  timeout: 10000
})
// 请求拦截器
request.interceptors.request.use((config) => {
  if (store.getters.token) {
    config.headers.Authorization = `Bearer ${store.getters.token}`
  }
  return config
}, (error) => {
  return Promise.error(error)
})
// 响应拦截器
request.interceptors.response.use((response) => {
  Toast.success('登陆成功')
  return response.data
}, (error) => {
  Toast.fail(error.response.data.message)
  return Promise.reject(error)
})

export default request
